<template>
  <div class="upload-demo">
    <div class="title">如是OCR</div>
    <el-steps class="steps" :active="activeStep" finish-status="success" simple>
      <el-step style="width: 160px;" title="选择文件" />
      <el-step style="width: 160px;" title="选择版面" />
      <el-step style="width: 160px;" title="选择引擎" />
    </el-steps>
    <div class="every" style="display: flex; align-items: center; justify-content: center; height: 45vh;">
      <template v-if="activeStep === 0">
        <Document />
      </template>
      <template v-else-if="activeStep === 1">
        <Page />
      </template>
      <template v-else-if="activeStep >= 2">
        <Engine />
      </template>
    </div>
    <div class="head">
      <el-button-group class="change">
        <el-button type="primary" round :icon="ArrowLeft" class="head-item" @click="prevStep">上一步</el-button>
        <el-button type="primary" round class="head-item" @click="nextStep"
          v-loading.fullscreen.lock="fullscreenLoading">
          <!-- 动态更新按钮文本 -->
          {{ activeStep >= 2 ? '开始OCR' : '下一步' }}
          <el-icon class="el-icon--right">
            <ArrowRight />
          </el-icon>
        </el-button>
      </el-button-group>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { ArrowLeft, ArrowRight } from '@element-plus/icons-vue'
import Document from './Ocr/Document.vue';
import Engine from './Ocr/Engine.vue';
import Page from './Ocr/Page.vue';

const activeStep = ref(0)
const fullscreenLoading = ref(false)

const nextStep = () => {
  if (activeStep.value < 2) {
    activeStep.value++
  } else if (activeStep.value === 2) {
    fullscreenLoading.value = true
    setTimeout(() => {
      fullscreenLoading.value = false
    }, 2000)
    activeStep.value++ // 增加activeStep
  }
}

const prevStep = () => {
  if (activeStep.value > 0) {
    activeStep.value--
  }
}

const openFullScreen = () => {
  fullscreenLoading.value = true
  setTimeout(() => {
    fullscreenLoading.value = false
    // 可以在这里执行其他操作，如发送数据等
  }, 2000)
}
</script>

<style scoped>
.title {
  font-size: clamp(40px, 2vw, 60px);
  font-weight: 600;
  margin-bottom: 20px;
}

.steps {
  margin-bottom: 5vh;
}

.upload-demo {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 500px;
  max-width: 900px;
  margin-top: 3vh;
}

.el-icon--upload {
  height: 20vh;
  width: 20vw;
}

.el-upload__text {
  font-size: clamp(15px, 2vw, 25px);
}

.el-upload__tip {
  font-size: clamp(15px, 0.8vw, 25px);
}

.change {
  margin-top: 5vh;
  width: 40vw;
  height: 60px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
}

.head-item {
  height: 50px;
  width: 15vw;
  min-width: 150px;
  max-width: 200px;
}


@media (max-width:400px) {
  .upload-demo {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: auto;
    max-width: none;
    margin-top: 10vh;
    width: 100%;
  }

  .steps {
    width: 50vw;
    margin-bottom: 0;
  }

  .change {
    margin-top: 0;
  }

  .title {
    font-size: 6vw;
  }

  .every {
    width: 80%;
  }

  .head-item {
    height: 40px;
    width: 15vw;
    min-width: 100px;
    max-width: 200px;
  }
}
</style>